package co.atguigu.es;

import lombok.Data;
import org.apache.http.HttpHost;
import org.elasticsearch.client.RestClient;
import org.elasticsearch.client.RestClientBuilder;
import org.elasticsearch.client.RestHighLevelClient;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.elasticsearch.config.AbstractElasticsearchConfiguration;

/**
 * @author LiuYunXin
 * @create 2022-05-31-0:22
 */
@ConfigurationProperties(prefix = "elasticsearch")
@Configuration
@Data

public class ElasticsearchConfig extends AbstractElasticsearchConfiguration {
    private String host = "127.0.0.1";
    private Integer port = 9200;
    // @Value("${elasticsearch.host}")
    // private String host ;
    // @Value("${elasticsearch.port}")
    // private Integer port;

    @Override
    public RestHighLevelClient elasticsearchClient() {
        RestClientBuilder builder = RestClient.builder(new HttpHost(host,port));
        RestHighLevelClient restHighLevelClient = new RestHighLevelClient(builder);
        return restHighLevelClient;
    }
}
